<template>
    <div>
        <div class="layout">
            <Menu  mode="horizontal" theme="dark">
                 <div class="layout-logo">游戏资讯分享平台(管理员登录)</div>
            </Menu>
        </div>

        <div>
            <div class="kuang">
                <Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
                    <Form-item prop="user">
                        <Input type="text" id="Username" v-model="formInline.user" placeholder="Username"/>
                    </Form-item>
                    <Form-item prop="password">
                        <Input type="password" id="password" v-model="formInline.password" placeholder="Password"/>
                    </Form-item>
                    <Form-item>
                        <Button type="primary" @click="handleSubmit('formInline')">登录</Button>
                    </Form-item>
                     <Form-item>
                        <a @click="Login('Login')" type="primary">用户登录</a>
                    </Form-item>
                </Form>
            </div>
        </div>
    </div>
</template>
<script>
    import axios from 'axios'

    export default {
        data () {
            return {
                list:[],
                formInline: {
                    user: 'admin',
                    password: 'admin'
                },
                ruleInline: {
                    user: [
                        { required: true, message: '请填写用户名', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请填写密码', trigger: 'blur' },
                        { type: 'string', min: 6, message: '密码长度不能小于6位', trigger: 'blur' }
                    ]
                },
                value3:false,
                personsFormItem: {
                    username: '',
                    sex: '',
                    phone: '',
                    email: '',
                    zone: '',
                    password: ''
                },
                personsNum:0
            }
        },
        methods: {
            handleSubmit(formInline) {
               
                this.upTitleAreaResult = this.formInline;
                var Username = this.upTitleAreaResult.user;
                var password = this.upTitleAreaResult.password;
                console.log(Username,password)
                axios('http://localhost:8081/managerLogin?username='+Username+'&password='+password).then((res) =>{
                    var sessionStorage = window.sessionStorage;  
                    sessionStorage.setItem('userId',res.data);
                    console.log(res.data);
                    if(res.data>0){
                        this.$Message.success('登录成功!');
                        this.$router.replace('/ManagerHome');
                    }else{
                        this.$Message.error('表单验证失败!');
                    }
                })
                
            },
            personsSubmit(personsFormItem){
                 console.log(this.personsFormItem);
                    let Persons = JSON.stringify({
                        username : this.personsFormItem.username,
                        email : this.personsFormItem.email,
                        phone : this.personsFormItem.phone,
                        sex : this.personsFormItem.sex,
                        zone :this.personsFormItem.zone,
                        password : this.personsFormItem.password
                });

                //  axios.post('http://localhost:8081/personsAdd', Persons,{
                //      headers: {
                //          "Content-Type": "application/json;charset=utf-8"  
                //          }
                //         }) .then((res)=> {
                //          this.personsNum = res.data;
                //          this.value3=false;
                //        if(this.personsNum==1){
                //             this.$Modal.confirm({
                //                 title: '注册成功！',
                //                 loading: false
                //             });
                //         }else if(this.personsNum==3){
                //             this.$Modal.confirm({
                //                 title: '您输入的用户名已存在！请重新输入！',
                //                 loading: false
                //             });
                //         }else{
                //             this.$Modal.confirm({
                //                 title: '创建失败！',
                //                 loading: false
                //             });
                //         }
                //     }).catch(function(error) {
                //         console.log(error);
                //     });
                
                //  axios.post('http://localhost:8081/personsAdd',{user}).then((res) =>{
                //         this.personsNum = res.data;
                //     if(this.personsNum==1){
                //         this.$Modal.confirm({
                //             title: '注册成功！',
                //             loading: false
                //         });
                //     }else if(this.personsNum==3){
                //         this.$Modal.confirm({
                //             title: '您输入的用户名已存在！请重新输入！',
                //             loading: false
                //         });
                //     }else{
                //         this.$Modal.confirm({
                //             title: '创建失败！',
                //             loading: false
                //         });
                //     }
                // })

            },
            Login(){
                 this.$router.push({
                path: `/` })
            }
        }
    }
</script>

<style>
.layout-logo{
    color: aliceblue;
    text-align: center;
    font-size: 20px;
    background-color:transparent;
}
.kuang{
    width: 200px;
    height: 100px;
    position: absolute;   
            top: 30%;   
            left: 43%;
    text-align: center;
}

</style>